#ifndef __SEQLIST_H__
#define __SEQLIST_H__

#include "Common.h"
#include "List.h"
#include "Exception.h"

NAME_SPACE_BEGIN

template <typename T>
class SeqList : public List<T>
{
public:
	using base_List_type = List<T>;

	using value_type		= base_List_type::value_type;
	using pointer			= base_List_type::pointer;
	using const_pointer		= base_List_type::const_pointer;
	using reference			= base_List_type::reference;
	using const_reference	= base_List_type::const_reference;

public:
	virtual bool insert(int i, const_reference e) {
		bool ret = ((0 <= i) && (i <= m_length));
		ret = ret && (m_length < capacity());
		if (ret)
		{
			for (int p = m_length - 1; p >= i; p--)
			{
				m_array[p + 1] = m_array[p];
			}
			m_array[i] = e;
			m_length++;
		}
		return ret;
	}
	virtual bool remove(int i) {
		bool ret = ((0 <= i) && (i <= m_length));
		if (ret)
		{
			for (int p = i; p < m_length - 1; p++)
			{
				m_array[p] = m_array[p + 1];
			}
			m_length--;
		}
		return ret;
	}
	virtual bool set(int i, const_reference e) {
		bool ret = ((0 <= i) && (i <= m_length));
		if (ret)
		{
			m_array[i] = e;
		}
		return ret;
	}
	virtual bool get(int i, reference e) const
	{
		bool ret = ((0 <= i) && (i <= m_length));
		if (ret)
		{
			e = m_array[i];
		}
		return ret;
	}

	virtual int find(const T& e)  const
	{
		int ret = -1;
		for (int i = 0; i < m_length; i++)
		{
			if (m_array[i] == e)
			{
				ret = i;
				break;
			}
		}
		return ret;
	}

	virtual int  length() const {
		return m_length;
	}
	virtual void clear() {
		m_length = 0;
	}

	reference operator[](int i) {
		if ((0 <= i) && (i < m_length))
		{
			return m_array[i];
		}
		else
		{
			THROW_EXCEPTION(IndexOutOfBoundsException, "Parameter i is invalid ...");
		}
	}

	reference operator[](int i) const
	{
		return const_cast<SeqList<value_type>&>(*this)[i];
	}

	virtual int	 capacity() const = 0;

protected:
	pointer m_array;
	int m_length;
};


NAME_SPACE_END


#endif
